package com.agent.user.controller.app;

import com.agent.common.result.ApiResponse;
import com.agent.common.utils.UserInfoUtils;
import com.agent.user.dto.UserAssetRequest;
import com.agent.user.service.UserAssetService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 用户资产控制器
 * @author Jeff_Wan
 * @description 提供用户资产相关接口
 */
@RestController
@RequestMapping("/assets")
@RequiredArgsConstructor
public class UserAssetController {
    private final UserAssetService userAssetService;
    
    /**
     * 上传用户资产
     * @param userId 用户ID
     * @param file 上传的文件
     * @return 资产ID
     */
//    @PostMapping("/upload")
    public ApiResponse<Long> uploadAsset(
            @RequestParam Long userId,
            @RequestParam MultipartFile file) throws IOException {
        
        // 实际项目中baseStoragePath应从配置读取
        String baseStoragePath = "/opt/storage";
        Long assetId = userAssetService.uploadUserAsset(userId, file, baseStoragePath);
        return ApiResponse.success(assetId);
    }

    /**
     * 记录用户资产信息
     * @param request 上传的资料信息
     * @return 资产ID
     */
    @PostMapping("/record")
    public ApiResponse<Long> recordUserAsset(@RequestBody UserAssetRequest request) {
        request.setUserId(UserInfoUtils.getUserId());
        boolean result = userAssetService.recordUserAsset(request);
        return ApiResponse.judge(result);
    }
}